﻿using Basic.HrModel.DB;
using Basic.HrModel.SignatureFile;
using Basic.HrRemoteModel.EmpSignatureFile.Model;
using WeDonekRpc.Client;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.IdGenerator;
using WeDonekRpc.Model;
using WeDonekRpc.SqlSugar;

namespace Basic.HrDAL.Repository
{
    internal class EmpSignatureFileDAL : BasicDAL<DBEmpSignatureFile, long>, IEmpSignatureFileDAL
    {
        public EmpSignatureFileDAL ( IRepository<DBEmpSignatureFile> basicDAL ) : base(basicDAL, "emp.sign.file")
        {
        }
        public Result[] Query<Result>(long empId, SignQueryParam query,IBasicPage paging,out int count) where Result : class
        {
            paging.InitOrderBy("Id", true);
            return _BasicDAL.Query<Result>(query.ToWhere(empId), paging, out count);
        }
        public long Add ( SignatureFileAdd add )
        {
            DBEmpSignatureFile data = add.ConvertMap<SignatureFileAdd, DBEmpSignatureFile>();
            data.Id = IdentityHelper.CreateId();
            data.AddTime = DateTime.Now;
            this._BasicDAL.Insert(data);
            return data.Id;
        }
        public void Drop ( long id )
        {
            if ( !this._BasicDAL.Update(a => a.IsDrop == true, a => a.Id == id) )
            {
                throw new ErrorException("hr.emp.sign.file.drop.fail");
            }
        }
    }
}
